package com.burger.counter.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.burger.counter.beans.Region;
import com.burger.counter.business.RegionBusiness;
import com.burger.counter.dao.RegionDao;

public class RegistrationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public RegistrationServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {		
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {		
		System.out.println("i am in servlet");
		RegionBusiness regionBI = new RegionBusiness();
		Region regionList[] =null;
		HttpSession session = request.getSession(true);  
		try {
			regionList = regionBI.getRegionDetails();
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("region size" +regionList);		
		Hashtable<Integer,String> regionDetails = new Hashtable<Integer,String>();
		for(int i =0 ;i<regionList.length;i++)
		{
			regionDetails.put(regionList[i].getRegionId(), regionList[i].getRegionName());
			System.out.println(regionList[i].getRegionId() + "" + regionList[i].getRegionName() );
		}
		
		request.getSession().setAttribute("regionData", regionDetails);
		
		
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Registration.jsp");
		dispatcher.forward(request, response);
	}

}
